import csv
import yaml
import json
import openpyxl
from icecream import ic
from openpyxl.workbook import Workbook
from config import constant_file


class ReadFileData:

    def __init__(self):
        '''
        先获取数据文件地址
        '''
        pass

    def read_csv(self,file_path):
        data=[]
        with open(file_path,encoding='utf-8') as f:
            reader=csv.reader(f,delimiter='#')
            first_row=next(reader)  # 跳过标题行
            for row in reader:
                dict={key:value for key,value in zip(first_row,row)}
                data.append(dict)
        return data

    def read_xls(self,file_path):
        workbook=openpyxl.load_workbook(file_path)  # type: Workbook
        sheet=workbook.active
        head=[cell.value for cell in sheet[1]]
        print(head)

    def read_json(self,file_path:str) ->dict:
        with open(file_path,encoding='utf-8') as f:
            data=json.load(f)
        return data
#
#
# ic(ReadFileData().read_json(r'D:\Programming_soft\python_auto_test_demo\school_project\Common\operate_file\test_data.json'))

# r'D:\\Programming_soft\\python_auto_test_demo/Common/operate_file/test_data.json'
# D:\Programming_soft\python_auto_test_demo\school_project\Common\operate_file\test_data.json